<template>
	<view style="background: linear-gradient(to top,#172349,#1d2e55,#203f5f,#4f5e72);">
	<view class="login">
		<view class="login-container">
			<view class= "login-head">
				<text>欢迎登录</text>
			</view>
			<view class="login-title">
				<view class= "login-font">
					<text style="font-family:Kristen ITC;  font-family:Kristen ITC;">Welcome to</text>
				</view>
				<view class= "login-font" style="margin-top: 20rpx; margin-top: 20rpx; font-family: 华文楷体; font-weight: bold;">
					<text>衣碳揪镜</text>
				</view>
				<view class= "login-font" style="margin-top: 20rpx; font-family: 华文楷体;">
					<text style="font-size: 36rpx;">让服装产品的碳足迹清澈如镜</text>
				</view>
			</view>
			<!-- <image src="@/static/imgs/Snipaste_2023-04-13_19-34-22.jpg"></image> -->
		</view>
			<view class="input-info" style="margin-top: 60rpx;">
				<text class="login_name">手机号 </text>
				<image class="login_button" ></image>
				<input  class="inputbox" v-model="telephone" maxlength="11"/>
			</view>
			<view class="input-info">
				<text space="ensp" decode="true" class="login_name">密&ensp;&ensp;码</text>
				<image class="login_button"></image>
				<input class="inputbox" maxlength="18" password="true" v-model="password" style="font-size: 56rpx; bottom: 35rpx;"/>
			</view>
			<view class="input-info">
				<text style="margin-right: 70rpx; font-size: 30rpx;" @click="register">注册账户</text>
				<text style="margin-left: 70rpx; font-size: 30rpx;" @click="forget_pas">忘记密码</text>
			</view>
			<view class="input-info" style="margin-top: 30rpx;">
				<text class="login_name" style="left: 22%;  width: 30%; padding: 20rpx; border-radius: 50rpx; padding-left: 170rpx; background-color: rgb(79, 94, 114,0.3);" @click="Login ">登录</text>
				<image class="login_button"  style="width: 35%;" @click="Login"></image>
			</view>
	</view>
		<view class="img" style="height: 20vh; width: 100%;">
			<image src="../../static/imgs/33.png" style= "width: 125%; height: 117%; ime-mode: ; margin-left: -100rpx;" mode="aspectFill" ></image>
		</view>
	</view>
</template>

<script>
	
	var _self;
	
import {login as loginApi} from '@/api/user'
import store from '../../store';
	
	export default {
		data() {
			return {
				flag:false,
				telephone:'',
				password:'',
				cid:'',
				uid:''
			}
		},
		onLoad() {
			_self=this
		},
		onPullDownRefresh() {
				URL:'/pages/login/login'
				setTimeout(function () {
					uni.stopPullDownRefresh();
				}, 1000);
		},
		methods: {
			// GoToIndex(){
			// 	if(this.telephone=='' || this.password==''){
			// 		uni.showToast({
			// 				title: '请输入登录信息！',//显示的文字
			// 		        duration: 1000,  //显示多少毫秒，默认1500毫秒，时间到自动隐藏
			// 		        icon: "error"  ,//自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
			// 		})
			// 	}else{
			// 		console.log(777)
			// 		this.flag=false
			// 		uni.switchTab({
			// 			url: '/pages/index/index'
			// 		})
			// 	}
			// },
			async Login(){
				if(this.telephone=='' || this.password==''){
						uni.showToast({
								title: '请输入登录信息！',//显示的文字
						        duration: 1000,  //显示多少毫秒，默认1500毫秒，时间到自动隐藏
						        icon: "error"  ,//自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						})
				}else{
					var phone=this.telephone;
					var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
					if(strTemp.test(phone)){
						const data ={
							telephone:this.telephone,
							password:this.password
						}
						const res = await loginApi(data);
						// console.log(res);
						
						if(res.status === this.API_STATUS_CODE.SUCCESS){
							uni.switchTab({
								url: '/pages/index/index'
							})
							console.log('登录成功')
							this.$store.dispatch('asyncUpdateUser',{cid:res.cid , uid:res.uid})
							// console.log(res.cid)
							// console.log(res.uid)
							// console.log("$store.getters.cid")
							// console.log(this.$store.getters.getUser.cid)
						}else{
							uni.showToast({icon:'none',title:'账号或密码错误'});
						}
					}else{
						uni.showToast({icon:'none',title:'请输入正确的电话'});
						return false
					}
					
				}
			},
			register(){
				uni.navigateTo({
					url:'/pages/login/register'
				})
			},
			forget_pas(){
				uni.showToast({
						title: '请联系管理员！',//显示的文字
				        duration: 1000,  //显示多少毫秒，默认1500毫秒，时间到自动隐藏
				        icon: "error"  ,//自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
				})
			}
		},
		components: {
		},
	}
</script>

<style lang ="scss" scoped>
	/* @import "@/static/iconfont/iconfont.css"; */
	
		.login{
			
			overflow: hidden;
			width: 100vw;  
			height:77vh;
			text-align: center;
			box-sizing: border-box;
			
			.login-container{
				height: 450rpx;
				width: 100vw;  
				.login-head{
					
					width: 100%;
					height: 180rpx;
					line-height: 180rpx;
					text{
						height: 75rpx;
						line-height: 250rpx;
						width: 75rpx;
						text-align: center;
						margin-top: 50rpx;
						font-size: 42rpx;
						color: #ffffff;
					}
				}
				.login-title{
					height: 300rpx;
					width: 100%;
					margin-top: 40rpx;
					.login-font{
						height: 80rpx;
						width: 100%;
						line-height: 80rpx;
						text{
							width: 60%;
							height: 80rpx;
							line-height: 80rpx;
							color: white;
							text-align: center;
							font-size: 72rpx;
						}
					}
				}
			}
			.input-info {
				position: relative;
				margin-top: 20rpx;
				.login_button {
					width: 85%;
					height: 100rpx;
					margin-top: 20rpx;
				}
				
				.login_name{
					position: absolute;
					display: block;
					width: 35%;
					left: 160rpx;
					bottom: 35rpx;
					color: #ffffff;
					text-align: left;
					font-size: 40rpx;
				}
				.inputbox {
					position: absolute;
					display: block;
					line-height: 100rpx;
					width: 40%;
					left: 300rpx;
					font-size: 43rpx;
					bottom: 37rpx;
					color: #ffffff;
					border-bottom: 2rpx solid #b6b6b6;
					text-align: left;
				}
				text{
					color: white;
				}
			}
		}
</style>